package com.example.flower_shop.controller.adm;

import com.example.flower_shop.common.PageResult;
import com.example.flower_shop.service.adm.AdminOrderService;
import com.example.flower_shop.vo.order.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "后台订单管理")
@RestController
@RequestMapping("/api/admin/order")
public class AdmOrderController {

    @Resource
    private AdminOrderService adminOrderService;

    @GetMapping
    @Operation(summary = "订单列表", method = "GET")
    public PageResult<AdmOrderPageResp> orderList(@Valid AdmOrderPageReq req) {
        return adminOrderService.orderList(req);
    }

    @GetMapping("/detail/{orderId}")
    @Operation(summary = "订单详情", method = "GET",
            parameters = {
                    @Parameter(name = "orderId", description = "订单ID", required = true,
                            in = ParameterIn.PATH)
            })
    public List<AdmOrderDetailResp> orderDetail(@PathVariable Long orderId) {
        return adminOrderService.orderDetail(orderId);
    }

    @PostMapping("/deliver")
    @Operation(summary = "发货", method = "POST")
    public void deliver(@Valid DeliverOrderReq req) {
        adminOrderService.deliver(req);
    }

    @PostMapping
    @Operation(summary = "处理退款", method = "POST")
    public void handleRefund(@Valid HandleOrderReq req) {
        adminOrderService.handleRefund(req);
    }

}
